Skip to content

Conversation

@Dan-Knott
Copy link
Contributor

Problem

When parsing PostgreSQL function defaults, pg_proc.proargdefaults converted with pg_get_expr() returns a single comma-separated string containing all default values, rather than an array.

This creates several challenges:

  1. The default values need to be split from the comma-separated string
  2. These values must then be aligned to the rightmost input arguments (since only trailing arguments can have defaults in PostgreSQL)
  3. Edge cases exist where commas might legitimately appear within default values themselves, making naive string splitting unreliable

Solution

Instead of parsing and realigning the comma-separated string, this PR uses PostgreSQL's pg_get_function_arg_default() function to retrieve the default value for each argument individually. This function:

  • Takes an argument position and returns the default for that specific argument
  • Returns the properly formatted default expression
  • Avoids any ambiguity around parsing comma-separated values
  • Eliminates the need for complex right-alignment logic

The column pg_proc.proargdefaults when converted with pg_get_expr returns a comma separated string of default values. This list of values then needs to be aligned to the right most input argument. To avoid this complex rearangement, and avoid any potential edge cases where ',' might be in the default value, the function pg_get_function_arg_default is used to check for a default for each argument.
@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.80%. Comparing base (d8ab535) to head (a389397).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #132   +/-   ##
=======================================
  Coverage   89.79%   89.80%           
=======================================
  Files          86       86           
  Lines        4096     4099    +3     
  Branches      850      850           
=======================================
+ Hits         3678     3681    +3     
  Misses        338      338           
  Partials       80       80           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Owner

@DanCardin DanCardin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

@DanCardin DanCardin merged commit eea161c into DanCardin:main Dec 4, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants